<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <el-dialog :visible.sync="crud.props.searchToggle"  close-on-click-modal title="搜索" width="50%">
        <el-form size="small" label-width="70px">
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12"  v-if="dateType === '1'">
              <el-form-item label="业务日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.startDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.endDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" v-if="dateType === '2'">
              <el-form-item label="审核日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.auditStartTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.auditEndTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="日期类型">
                <el-select v-model="query.dateType" collapse-tags @change="tabDate"  class="edit-input" placeholder="请选择日期类型" style="width: 100%;">
                  <el-option label="业务日期" value="1"/>
                  <el-option label="审核日期" value="2"/>
                </el-select>
              </el-form-item>
            </el-col>
<!--            <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" >-->
<!--              <el-form-item label="发货日期">-->
<!--                <div class="flex flex-row">-->
<!--                  <el-date-picker-->
<!--                    v-model="query.auditStartTime"-->
<!--                    align="right"-->
<!--                    unlink-panels-->
<!--                    class="fl1"-->
<!--                    format="yyyy - MM - dd "-->
<!--                    value-format="yyyy-MM-dd"-->
<!--                    default-value-->
<!--                    range-separator=""-->
<!--                    placeholder="开始日期"-->
<!--                  />-->
<!--                  <el-date-picker-->
<!--                    v-model="query.auditEndTime"-->
<!--                    align="right"-->
<!--                    unlink-panels-->
<!--                    class="fl1"-->
<!--                    format="yyyy - MM - dd "-->
<!--                    value-format="yyyy-MM-dd"-->
<!--                    default-value-->
<!--                    range-separator=""-->
<!--                    placeholder="结束日期"-->
<!--                  />-->
<!--                </div>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="仓库">
                <table-select
                  :tableColumns="[{prop:'code',label:'编码',width:'100'},{prop:'name',label:'名称',width: '280'}]"
                  :value.sync="query.warehouseIds"
                  placeholder="请选择仓库"
                  url="/api/dropDown/basWarehouseList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="库区">
<!--                <zSelect multiple :value.sync="locationIds"  url="/api/dropDown/basLocationList" style="width:  100%;"/>-->
                <table-select
                  :tableColumns="[{prop:'code',label:'库区编码',width:'100'},{prop:'name',label:'库区名称',width: '280'}]"
                  :value.sync="query.locationIds"
                  placeholder="请选择库区"
                  url="/api/dropDown/basLocationList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="库位">
<!--                <zSelect multiple :value.sync="storehouseIds"  url="/api/dropDown/basStorehouseList" style="width:  100%;"/>-->
                <table-select
                  :tableColumns="[{prop:'code',label:'库位编码',width:'100'},{prop:'name',label:'库位名称',width: '280'}]"
                  :value.sync="query.storehouseIds"
                  placeholder="请选择库位"
                  url="/api/dropDown/basStorehouseList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商贸公司">
                <table-select
                  :tableColumns="[{prop:'code',label:'编码',width:'100'},{prop:'name',label:'名称',width: '280'}]"
                  :value.sync="query.fCustomerIds"
                  placeholder="请选择商贸公司"
                  url="/api/dropDown/basCustomerList"
                  :params="{type:2}"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品品牌">
                <table-select
                  :tableColumns="[{prop:'code',label:'品牌编码',width:'100'},{prop:'name',label:'品牌名称',width: '280'}]"
                  :value.sync="query.goodsBrandIds"
                  placeholder="请选择品牌"
                  url="/api/dropDown/basGoodsBrandList"
                ></table-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品分类">
                <treeselect
                  v-model="goodsTypeIds"
                  :options="areaList"
                  placeholder="商品分类"
                  style="width: 100%"
                  :normalizer="normalizer"
                  multiple
                  @input="getgoodsType"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="商品">
                <table-select
                  :tableColumns="[{prop:'goodsCode',label:'商品编码',width:'100'},{prop:'goodsName',label:'商品名称',width: '280'}]"
                  labelKey="goodsName"
                  valueKey="goodsId"
                  :value.sync="query.goodsIds"
                  placeholder="请选择商品"
                  url="/api/dropDown/basGoodsListForAdd"
                />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <rrOperation :crud="crud"/>
            </el-col>
          </el-row>
        </el-form>
      </el-dialog>
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="id">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库id">
            <el-input v-model="form.warehouseId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库编码">
            <el-input v-model="form.warehouseCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库名称">
            <el-input v-model="form.warehouseName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="库区id">
            <el-input v-model="form.locationId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="库区编码">
            <el-input v-model="form.locationCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="库区名称">
            <el-input v-model="form.locationName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="库位id">
            <el-input v-model="form.storehouseId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="库位编码">
            <el-input v-model="form.storehouseCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="库位名称">
            <el-input v-model="form.storehouseName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品id" prop="goodsId">
            <el-input v-model="form.goodsId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品编码">
            <el-input v-model="form.goodsCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品名称">
            <el-input v-model="form.goodsName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="包装类型(1:纸箱 2:塑箱 3:其他)">
            <el-input v-model="form.packageType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="条形码">
            <el-input v-model="form.barcode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱装条形码">
            <el-input v-model="form.boxBarcode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="助记符">
            <el-input v-model="form.helpSign" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="规格型号">
            <el-input v-model="form.model" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌id">
            <el-input v-model="form.goodsBrandId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌编码">
            <el-input v-model="form.goodsBrandCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品品牌名称">
            <el-input v-model="form.goodsBrandName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类id">
            <el-input v-model="form.goodsTypeId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类编码">
            <el-input v-model="form.goodsTypeCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品分类名称">
            <el-input v-model="form.goodsTypeName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型id">
            <el-input v-model="form.goodsTagId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型编码">
            <el-input v-model="form.goodsTagCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品类型名称">
            <el-input v-model="form.goodsTagName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位id">
            <el-input v-model="form.boxUnitId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位编码">
            <el-input v-model="form.boxUnitCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱单位名称">
            <el-input v-model="form.boxUnitName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="箱数单位计量数">
            <el-input v-model="form.boxUnitCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位id">
            <el-input v-model="form.mainUnitId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位编码">
            <el-input v-model="form.mainUnitCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位名称">
            <el-input v-model="form.mainUnitName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主单位计量数">
            <el-input v-model="form.mainUnitCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期初数量">
            <el-input v-model="form.beginGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期初箱数">
            <el-input v-model="form.beginBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期初箱单位数量">
            <el-input v-model="form.beginBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期初主单位数量">
            <el-input v-model="form.beginMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期初含税金额">
            <el-input v-model="form.beginTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期初未税金额">
            <el-input v-model="form.beginNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期初税额">
            <el-input v-model="form.beginTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库数量">
            <el-input v-model="form.enterGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库箱数">
            <el-input v-model="form.enterBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库箱单位数量">
            <el-input v-model="form.enterBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库主单位数量">
            <el-input v-model="form.enterMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库含税金额">
            <el-input v-model="form.enterTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库未税金额">
            <el-input v-model="form.enterNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库税额">
            <el-input v-model="form.enterTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库数量">
            <el-input v-model="form.returnGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库箱数">
            <el-input v-model="form.returnBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库箱单位数量">
            <el-input v-model="form.returnBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库主单位数量">
            <el-input v-model="form.returnMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库含税金额">
            <el-input v-model="form.returnTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库未税金额">
            <el-input v-model="form.returnNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出库税额">
            <el-input v-model="form.returnTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期末数量">
            <el-input v-model="form.endGoodsCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期末箱数">
            <el-input v-model="form.endBoxCount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期末箱单位数量">
            <el-input v-model="form.endBoxNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期末主单位数量">
            <el-input v-model="form.endMainNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期末含税金额">
            <el-input v-model="form.endTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期末未税金额">
            <el-input v-model="form.endNoTaxAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="期末税额">
            <el-input v-model="form.endTax" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="商品备注">
            <el-input v-model="form.goodsRemark" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"></vue-context-menu>

      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header"  @tabSave="saveHead" />
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table"
                stripe
                border show-summary :summary-method="crud.sumRow"
                @header-dragend="changeColWidth"
                @contextmenu.native="showMenu"
                :data="crud.data"
                size="small"
                style="width: 100%;"
                height="700"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" width="55" label="序号"/>
        <el-table-column

          v-if="item.visible"
          v-for="(item, index) in header"
          :key="`col_${index}`"
          :prop="item.prop"
          :label="columnLabel(item)"
          :width="item.width + 'px'"
          :data-porp='item.prop'
          @contextmenu.native="showMenu"
          @header-dragend="changeColWidth"
        >
          <!-- 自定义渲染模版 -->
          <template slot-scope="scope">
            <!-- 当列key为 sort 时，渲染一个手柄icon -->
            <template v-if="item.prop =='sort'">
              <div class="handle_move">
                <i :class="scope.row['sort']" />
              </div>
            </template>
            <template v-else>
              <span v-if="item.type == 1" style="margin-left: 10px">{{scope.row[`${item.prop}`]}}</span>
              <span v-if="item.type == 2" style="margin-left: 10px">{{ parseTime(scope.row[`${item.prop}`])}}</span>
              <span v-if="item.type == 3" style="margin-left: 10px">{{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}</span>
            </template>
          </template>
        </el-table-column>

        <!--        <el-table-column v-if="columns.visible('id')" prop="id" label="id" />-->
<!--        <el-table-column v-if="columns.visible('warehouseId')" prop="warehouseId" label="仓库id" />-->
<!--        <el-table-column v-if="columns.visible('warehouseCode')" prop="warehouseCode" label="仓库编码" />-->
<!--        <el-table-column v-if="columns.visible('warehouseName')" prop="warehouseName" label="仓库名称" />-->
<!--        <el-table-column v-if="columns.visible('locationId')" prop="locationId" label="库区id" />-->
<!--        <el-table-column v-if="columns.visible('locationCode')" prop="locationCode" label="库区编码" />-->
<!--        <el-table-column v-if="columns.visible('locationName')" prop="locationName" label="库区名称" />-->
<!--        <el-table-column v-if="columns.visible('storehouseId')" prop="storehouseId" label="库位id" />-->
<!--        <el-table-column v-if="columns.visible('storehouseCode')" prop="storehouseCode" label="库位编码" />-->
<!--        <el-table-column v-if="columns.visible('storehouseName')" prop="storehouseName" label="库位名称" />-->
<!--        <el-table-column v-if="columns.visible('goodsId')" prop="goodsId" label="商品id" />-->
<!--        <el-table-column v-if="columns.visible('goodsCode')" prop="goodsCode" label="商品编码" />-->
<!--        <el-table-column v-if="columns.visible('goodsName')" prop="goodsName" label="商品名称" />-->
<!--        <el-table-column v-if="columns.visible('packageType')" prop="packageType" label="包装类型(1:纸箱 2:塑箱 3:其他)" />-->
<!--        <el-table-column v-if="columns.visible('barcode')" prop="barcode" label="条形码" />-->
<!--        <el-table-column v-if="columns.visible('boxBarcode')" prop="boxBarcode" label="箱装条形码" />-->
<!--        <el-table-column v-if="columns.visible('helpSign')" prop="helpSign" label="助记符" />-->
<!--        <el-table-column v-if="columns.visible('model')" prop="model" label="规格型号" />-->
<!--        <el-table-column v-if="columns.visible('goodsBrandId')" prop="goodsBrandId" label="商品品牌id" />-->
<!--        <el-table-column v-if="columns.visible('goodsBrandCode')" prop="goodsBrandCode" label="商品品牌编码" />-->
<!--        <el-table-column v-if="columns.visible('goodsBrandName')" prop="goodsBrandName" label="商品品牌名称" />-->
<!--        <el-table-column v-if="columns.visible('goodsTypeId')" prop="goodsTypeId" label="商品分类id" />-->
<!--        <el-table-column v-if="columns.visible('goodsTypeCode')" prop="goodsTypeCode" label="商品分类编码" />-->
<!--        <el-table-column v-if="columns.visible('goodsTypeName')" prop="goodsTypeName" label="商品分类名称" />-->
<!--        <el-table-column v-if="columns.visible('goodsTagId')" prop="goodsTagId" label="商品类型id" />-->
<!--        <el-table-column v-if="columns.visible('goodsTagCode')" prop="goodsTagCode" label="商品类型编码" />-->
<!--        <el-table-column v-if="columns.visible('goodsTagName')" prop="goodsTagName" label="商品类型名称" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitId')" prop="boxUnitId" label="箱单位id" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitCode')" prop="boxUnitCode" label="箱单位编码" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitName')" prop="boxUnitName" label="箱单位名称" />-->
<!--        <el-table-column v-if="columns.visible('boxUnitCount')" prop="boxUnitCount" label="箱数单位计量数" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitId')" prop="mainUnitId" label="主单位id" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitCode')" prop="mainUnitCode" label="主单位编码" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitName')" prop="mainUnitName" label="主单位名称" />-->
<!--        <el-table-column v-if="columns.visible('mainUnitCount')" prop="mainUnitCount" label="主单位计量数" />-->
<!--        <el-table-column v-if="columns.visible('beginGoodsCount')" prop="beginGoodsCount" label="期初数量" />-->
<!--        <el-table-column v-if="columns.visible('beginBoxCount')" prop="beginBoxCount" label="期初箱数" />-->
<!--        <el-table-column v-if="columns.visible('beginBoxNum')" prop="beginBoxNum" label="期初箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('beginMainNum')" prop="beginMainNum" label="期初主单位数量" />-->
<!--        <el-table-column v-if="columns.visible('beginTaxAmount')" prop="beginTaxAmount" label="期初含税金额" />-->
<!--        <el-table-column v-if="columns.visible('beginNoTaxAmount')" prop="beginNoTaxAmount" label="期初未税金额" />-->
<!--        <el-table-column v-if="columns.visible('beginTax')" prop="beginTax" label="期初税额" />-->
<!--        <el-table-column v-if="columns.visible('enterGoodsCount')" prop="enterGoodsCount" label="入库数量" />-->
<!--        <el-table-column v-if="columns.visible('enterBoxCount')" prop="enterBoxCount" label="入库箱数" />-->
<!--        <el-table-column v-if="columns.visible('enterBoxNum')" prop="enterBoxNum" label="入库箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('enterMainNum')" prop="enterMainNum" label="入库主单位数量" />-->
<!--        <el-table-column v-if="columns.visible('enterTaxAmount')" prop="enterTaxAmount" label="入库含税金额" />-->
<!--        <el-table-column v-if="columns.visible('enterNoTaxAmount')" prop="enterNoTaxAmount" label="入库未税金额" />-->
<!--        <el-table-column v-if="columns.visible('enterTax')" prop="enterTax" label="入库税额" />-->
<!--        <el-table-column v-if="columns.visible('returnGoodsCount')" prop="returnGoodsCount" label="出库数量" />-->
<!--        <el-table-column v-if="columns.visible('returnBoxCount')" prop="returnBoxCount" label="出库箱数" />-->
<!--        <el-table-column v-if="columns.visible('returnBoxNum')" prop="returnBoxNum" label="出库箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('returnMainNum')" prop="returnMainNum" label="出库主单位数量" />-->
<!--        <el-table-column v-if="columns.visible('returnTaxAmount')" prop="returnTaxAmount" label="出库含税金额" />-->
<!--        <el-table-column v-if="columns.visible('returnNoTaxAmount')" prop="returnNoTaxAmount" label="出库未税金额" />-->
<!--        <el-table-column v-if="columns.visible('returnTax')" prop="returnTax" label="出库税额" />-->
<!--        <el-table-column v-if="columns.visible('endGoodsCount')" prop="endGoodsCount" label="期末数量" />-->
<!--        <el-table-column v-if="columns.visible('endBoxCount')" prop="endBoxCount" label="期末箱数" />-->
<!--        <el-table-column v-if="columns.visible('endBoxNum')" prop="endBoxNum" label="期末箱单位数量" />-->
<!--        <el-table-column v-if="columns.visible('endMainNum')" prop="endMainNum" label="期末主单位数量" />-->
<!--        <el-table-column v-if="columns.visible('endTaxAmount')" prop="endTaxAmount" label="期末含税金额" />-->
<!--        <el-table-column v-if="columns.visible('endNoTaxAmount')" prop="endNoTaxAmount" label="期末未税金额" />-->
<!--        <el-table-column v-if="columns.visible('endTax')" prop="endTax" label="期末税额" />-->
<!--        <el-table-column v-if="columns.visible('goodsRemark')" prop="goodsRemark" label="商品备注" />-->
<!--        <el-table-column v-permission="['admin','reportWarehouseStock:edit','reportWarehouseStock:del']" label="操作" width="150px" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <udOperation-->
<!--              :data="scope.row"-->
<!--              :permission="permission"-->
<!--            />-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudReportWarehouseStock from '@/api/erp/reportWarehouseStock'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import Treeselect from '@riophae/vue-treeselect'
import {getBasGoodsTypeTree} from "@/api/erp/basGoodsType";
import {manyTableMixin} from "@/mixins/manyTableMixin";
import jTableColumnConfig from "@/components/jTableColumnConfig/jTableColumnConfig";
import { publicListKey } from "@/utils/key";
import { getTypeList } from '@/api/erp/basGoodsType'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '仓库收发存报表', url: 'api/reportWarehouseStock',
queryOnPresenterCreated:false,
  optShow: {
    add: false,
    edit: false,
    del: false,
    download: true,
    leadingIn: false,
    enable: false,
    disable: false,
    pass: false,
    reject: false,
    invalid: false,
    recover: false,
    downloadDetail: false,
    print: false,
    printDetail: false
  },
  sort: '',
  query:{
    dateType:'2',
    auditStartTime:new Date().toISOString().split('T')[0],
    auditEndTime:new Date().toISOString().split('T')[0],
  },
  crudMethod: { ...crudReportWarehouseStock }})
const defaultForm = { id: null, warehouseId: null, warehouseCode: null, warehouseName: null, locationId: null, locationCode: null, locationName: null, storehouseId: null, storehouseCode: null, storehouseName: null, goodsId: null, goodsCode: null, goodsName: null, packageType: null, barcode: null, boxBarcode: null, helpSign: null, model: null, goodsBrandId: null, goodsBrandCode: null, goodsBrandName: null, goodsTypeId: null, goodsTypeCode: null, goodsTypeName: null, goodsTagId: null, goodsTagCode: null, goodsTagName: null, boxUnitId: null, boxUnitCode: null, boxUnitName: null, boxUnitCount: null, mainUnitId: null, mainUnitCode: null, mainUnitName: null, mainUnitCount: null, beginGoodsCount: null, beginBoxCount: null, beginBoxNum: null, beginMainNum: null, beginTaxAmount: null, beginNoTaxAmount: null, beginTax: null, enterGoodsCount: null, enterBoxCount: null, enterBoxNum: null, enterMainNum: null, enterTaxAmount: null, enterNoTaxAmount: null, enterTax: null, returnGoodsCount: null, returnBoxCount: null, returnBoxNum: null, returnMainNum: null, returnTaxAmount: null, returnNoTaxAmount: null, returnTax: null, endGoodsCount: null, endBoxCount: null, endBoxNum: null, endMainNum: null, endTaxAmount: null, endNoTaxAmount: null, endTax: null, goodsRemark: null }
export default {
  name: 'ReportWarehouseStock',
  components: { pagination, crudOperation, rrOperation, udOperation, Treeselect, jTableColumnConfig },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(), manyTableMixin, publicListKey],
  dicts:['t_bas_goods_package_type'],
  data() {
    return {
      permission: {
        download: ['admin', 'reportWarehouseStock:download'],
      },
      rules: {
        goodsId: [
          { required: true, message: '商品id不能为空', trigger: 'blur' }
        ]
      } ,
      dateType:'2',
      areaList:null,
      dataExtent:[],
      warehouseIds:[],
      locationIds:[],
      goodsBrandIds:[],
      goodsTypeIds:[],
      goodsIds:[],
      storehouseIds:[],
      fCustomerIds:[]
    }
  },
  created() {
    const date = new Date().toISOString().split('T')[0]
    // this.dataExtent= [date,date],

    // this.$set(this.query,'auditStartTime',date)
    // this.$set(this.query,'auditEndTime',date)
    this.$set(this.query,'auditStartTime',date)
    this.$set(this.query,'auditEndTime',date)
    getTypeList({size:999}).then(res=>{

      this.areaList = res
    })
  },
  mounted() {
    this.crud.props.searchToggle = false
  },
  watch: {
    warehouseIds(){this.query.warehouseIds = this.warehouseIds.join(',')},
    locationIds(){this.query.locationIds = this.locationIds.join(',')},
    goodsBrandIds(){this.query.goodsBrandIds = this.goodsBrandIds.join(',')},
    goodsIds(){this.query.goodsIds = this.goodsIds.join(',')},
    storehouseIds(){this.query.storehouseIds = this.storehouseIds.join(',')},
    fCustomerIds(){this.query.fCustomerIds = this.fCustomerIds.join(',')}
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    tabDate(val){
      if (val === '1'){
        this.dateType = '1'
        this.$set(this.query,'auditStartTime',null)
        this.$set(this.query,'auditEndTime',null)
      }else {
        this.dateType = '2'
        this.$set(this.query,'startDate',null)
        this.$set(this.query,'endDate',null)
      }
    },
    // getValue(e){
    //   this.query.startDate = this.dataExtent[0]
    //   this.query.endDate = this.dataExtent[1]
    // },
    getgoodsType(val){
      let str=''
      console.log(this.areaList)
      val.forEach(item=>{
        const  itemNode=this.getTreeName(this.areaList,item)
        str=this.getNode(itemNode,str)
      })
      this.query.goodsTypeIds = str
      console.log(this.query.goodsTypeIds)
    },
    getTreeName(treeList,id){
      let _this=this
      for(let i=0;i<treeList.length;i++){
        let treeItem=treeList[i]
        if(treeItem.id===id){
          return treeItem
        }else{
          if(treeItem.children && treeItem.children.length>0){
            let res=_this.getTreeName(treeItem.children,id)
            if(res){
              return res
            }
          }
        }
      }
    },

    delgoodsType(node){
      const list = this.getNode(node,'').split(',')
      const oldList = this.query.goodsTypeIds.split(',')
      for(let i =oldList.length;i>0;i--){
        console.log(list)
        console.log(oldList[i])
        console.log(list.includes(oldList[i]))
        if (list.includes(oldList[i])){
          oldList.splice(i,1)
        }
      }
      this.query.goodsTypeIds = oldList.join(',')
      console.log(this.query.goodsTypeIds)
    },
    getNode(node,str){
      if (node.children){
        for (let i =0;i<node.children.length;i++){
          str = this.getNode(node.children[i],str)
        }
      }
      return str+=node.id+ ','
    },
    normalizer(node) {
      //去掉children=[]的children属性
      if (node.children == null || node.children.length == 0) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children
      }
    },
  }
}
</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
